package com.bbx.taxi.client.Task;

import android.app.Activity;
import android.util.Log;

import com.baidu.mapapi.model.LatLng;
import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.passanger.CarTypeBuild;
import com.bbx.api.sdk.model.passanger.Return.FAIL;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Location;
import com.bbx.api.sdk.net.base.BaseNetwork;
import com.bbx.api.sdk.net.base.HttpComm;
import com.bbx.api.sdk.net.passeger.conn.CancelReasonListNet;
import com.bbx.api.sdk.net.passeger.conn.CarTypeNet;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Activity.Main.IMainContract;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Activity.Main.IMainContract.RESETVIEW;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute.CjType;
import com.bbx.taxi.client.Bean.Message.ObserverListener.DATA_TYPE;
import com.bbx.taxi.client.Util.Tel;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickSingleListener;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog.OnLineClickLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyLineNotDialog.OnLineClickRightListener;

/**
 * @Path com.bbx.taxi.client.Task.MyCarTypeTask.java
 * @Author 严旭文
 * @Date 2016-9-19 下午5:22:07
 * @Company 蓝海（福建）信息技术有限公司
 * @Description 获取可用车型
 */
public class MyCarTypeTask extends BaseTask {
	public static final int CARTYPE_BC = 1;
	public static final int CARTYPE_SN = 3;
	public DATA_TYPE TYPE = DATA_TYPE.CARTYPE;
	private CarTypeBuild mCarTypeBuild;
	public static MyLineNotDialog mylinedialog;
	public static MyAlertDailog mydialog;
	private String line_id;
	/** 用于判断是否是当前的类型，城际，市内，快件 */
	private int view_id;
	/** 判断拼车，包车，顺风车 */
	private CjType citype;
	private boolean isCity;
	private IMainContract.ViewMain mMainView;

	public MyCarTypeTask(Activity context,IMainContract.ViewMain mMainView, int order_type, LatLng start,
			LatLng end, String line_id, boolean isCity, int view_id,
			CjType citype) {
		super(context);
		this.mMainView=mMainView;
		this.isCity = isCity;
		this.view_id = view_id;
		this.citype = citype;
		this.line_id = line_id;
		mCarTypeBuild = new CarTypeBuild(context);
		mCarTypeBuild.uid = MyApplication.getInstance().getUid();
		mCarTypeBuild.access_token = MyApplication.getInstance().getToken();
		mCarTypeBuild.order_type = order_type;
		Location Location_start = new Location();
		Location_start.lat = start.latitude;
		Location_start.lng = start.longitude;

		Location Location_end = new Location();
		Location_end.lat = end.latitude;
		Location_end.lng = end.longitude;
		mCarTypeBuild.start_location = Location_start;
		mCarTypeBuild.end_location = Location_end;
	}

	@Override
	public boolean isShow() {
		return false;
	}

	@Override
	public boolean isReturnString() {
		return false;
	}

	@Override
	public boolean condition() {
		try {
			MainActivity mainactivity = (MainActivity) context;
			MainAttribute main = MainAttribute.getInstance();
			if (mainactivity.mPresenter.getViewId() == view_id
					&& main.getCjType() == citype) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {

			return true;
		}
	}

	@Override
	public void request() {
		setType(TYPE, mCarTypeBuild);
	}

	@Override
	public void success(int status,Object object) {
		// TODO Auto-generated method stub

	}

	@Override
	public void failed(int status, String msg,String message) {
		MainActivity mainactivity = (MainActivity) context;
		MainAttribute main = MainAttribute.getInstance();
		//如果是市内则不弹窗，因为市内获取不到的时候会自动变成打表
		if ((status == -17 || status == -10)) {
			if(mainactivity.mPresenter.isCity()){
				if (mylinedialog == null) {
				mylinedialog = new MyLineNotDialog(context);
			}
			if (mylinedialog.isShowing())
				return;
			mylinedialog.setContent(message);
			mylinedialog.setLeftButtonText(context
					.getString(R.string.mydailog_besides));
			mylinedialog.setRightButtonText(context
					.getString(R.string.mydailog_telkf));
			mylinedialog
					.setOnLineClickLeftListener(new OnLineClickLeftListener() {
						@Override
						public void onLineClickLeft() {
							mylinedialog.dismiss();
						}
					});
			mylinedialog
					.setOnLineClickRightListener(new OnLineClickRightListener() {
						@Override
						public void onLineClickRight() {
							mylinedialog.dismiss();
							Tel.onTel_KF(context, line_id, isCity);
						}
					});
			mylinedialog.show();
			}else{
				if (mydialog == null) {
					mydialog = new MyAlertDailog(context);
				}
				mydialog.setTitle(context
						.getString(R.string.mydailog_title));
				mydialog.setContent(context
						.getString(R.string.price_no));
				mydialog.setSingle(context
						.getString(R.string.mydailog_know));
				mydialog.setOnClickSingleListener(new onClickSingleListener() {
					@Override
					public void onClickSingle() {
						mydialog.dismiss();
					}
				});
				mydialog.show();
				mMainView.resetView(RESETVIEW.end);
			}

		} else {
			ToastUtil.showToast(context, message);
			if(status!=HttpComm.TIMEOUT_CODE){
				mainactivity.resetView(RESETVIEW.end);
			}
		}
	}

	@Override
	public BaseNetwork getBaseNetwork() {
		return new CarTypeNet(context);
	}
}
